import { CRS } from "./CRS";
export class Earth extends CRS {
  wrapLng = [-180, 180];
  R = 6371000;
  // 利用余弦近似的球面定律计算两个地理点之间的距离
  distance(latlng1, latlng2) {
    const rad = Math.PI / 180,
      lat1 = latlng1.lat * rad,
      lat2 = latlng2.lat * rad,
      sinDLat = Math.sin(((latlng2.lat - latlng1.lat) * rad) / 2),
      sinDLon = Math.sin(((latlng2.lng - latlng1.lng) * rad) / 2),
      a =
        sinDLat * sinDLat + Math.cos(lat1) * Math.cos(lat2) * sinDLon * sinDLon,
      c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    return this.R * c;
  }
}
